//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <mantle.h>

// The 'uSize' is page-size alignment

UInt32 _DzAllocBootModuleSpace(UInt32 uSize)
{
    return GlobalAS::AllocB(uSize);
}

void _DzFreeBootModuleSpace(UInt32 uUAddr, UInt32 uSize)
{
    GlobalAS::FreeB(uUAddr, uSize);
}

ECode _DzMapBootModule(UInt32 uUAddr, UInt32 uSize, UInt32 uPAddr)
{
    CProcess *pProcess = GetCurrentProcess();
    assert(pProcess);
    return pProcess->m_AS.Remap(uUAddr, uSize, uPAddr,
                   MemoryMap_Fixed | MemoryMap_Shared, MemoryProtection_Read, NULL);
}

ECode _DzUnmapBootModule(UInt32 uUAddr, UInt32 uSize)
{
    CProcess *pProcess = GetCurrentProcess();
    assert(pProcess);
    return pProcess->m_AS.Unmap(uUAddr, uSize);
}

ECode _DzGetBootModule(const wchar_t *wszName, UInt32 *puAddr, UInt32 *puSize)
{
    virtaddr_t vaLimit;
    ECode ec = GetBootModule(wszName, (virtaddr_t *)puAddr, &vaLimit);
    if (SUCCEEDED(ec)) {
        *puSize = (UInt32)vaLimit - *puAddr;
    }
    return ec;
}
